package com.thoughtworks.Chapter3;

import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.util.function.Function;

/**
 * Created by yrzhang on 10/8/16.
 */
public class ExecuteAround {
    public String processFileLimited() throws IOException {
        BufferedReader br = new BufferedReader(new FileReader("resources/chapter3/data.txt"));
        return br.readLine();
    }

    public String processFile(BufferedReaderProcessor processor) throws IOException {
        BufferedReader br = new BufferedReader(new FileReader("resources/chapter3/data.txt"));
        return processor.process(br);
    }

    public String processFile2(Function<BufferedReader, String> reader) throws IOException {
        BufferedReader br = new BufferedReader((new FileReader("resources/chapter3/data.txt")));

        return reader.apply(br);
    }

    @FunctionalInterface
    public interface BufferedReaderProcessor {
        String process(BufferedReader reader) throws IOException;
    }
}
